/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('carbonfootprint', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AllowResponseBody = {
  data?: boolean(name='Data', example='true'),
  requestId?: string(name='RequestId', example='A009DA1A-46BD-5C72-A713-EEB82249120D'),
}

model AllowResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: AllowResponseBody(name='body'),
}

async function allowWithOptions(runtime: Util.RuntimeOptions): AllowResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'Allow',
    version = '2023-07-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function allow(): AllowResponse {
  var runtime = new Util.RuntimeOptions{};
  return allowWithOptions(runtime);
}

model GetSummaryDataRequest {
  endTime?: string(name='EndTime', description='The end of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-02-01 23:59:59.', example='2023-02-01 23:59:59'),
  group?: string(name='Group', description='The statistical dimension. A value of productCode specifies that statistics are collected based on cloud service. A value of region specifies that statistics are collected based on region. A value of subUid specifies that statistics are collected based on Resource Access Management (RAM) user. If you do not specify this parameter, statistics are collected based on Alibaba Cloud account.', example='productCode'),
  startTime?: string(name='StartTime', description='The beginning of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-01-01 00:00:00.', example='2023-01-01 00:00:00'),
  uids?: [ string ](name='Uids', description='The list of Alibaba Cloud account IDs whose data needs to be queried.(used after enabling multi-account management).'),
}

model GetSummaryDataShrinkRequest {
  endTime?: string(name='EndTime', description='The end of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-02-01 23:59:59.', example='2023-02-01 23:59:59'),
  group?: string(name='Group', description='The statistical dimension. A value of productCode specifies that statistics are collected based on cloud service. A value of region specifies that statistics are collected based on region. A value of subUid specifies that statistics are collected based on Resource Access Management (RAM) user. If you do not specify this parameter, statistics are collected based on Alibaba Cloud account.', example='productCode'),
  startTime?: string(name='StartTime', description='The beginning of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-01-01 00:00:00.', example='2023-01-01 00:00:00'),
  uidsShrink?: string(name='Uids', description='The list of Alibaba Cloud account IDs whose data needs to be queried.(used after enabling multi-account management).'),
}

model GetSummaryDataResponseBody = {
  data?: {
    aircraftConsumptionConversion?: string(name='AircraftConsumptionConversion', description='Converted aircraft carbon emissions.', example='2.5'),
    carConsumptionConversion?: string(name='CarConsumptionConversion', description='Converted car carbon emissions.', example='0'),
    lastMonthConsumptionConversion?: string(name='LastMonthConsumptionConversion', description='The carbon emissions in the previous month, in kgCO₂e.', example='301.83'),
    lastYearConsumptionConversion?: string(name='LastYearConsumptionConversion', description='The carbon emissions in the same month of the previous year, in kgCO₂e.', example='1074.53'),
    lastYearConsumptionConversionSum?: string(name='LastYearConsumptionConversionSum', description='The carbon emissions of the previous year, in kgCO₂e.', example='2844.58'),
    latestDataTime?: string(name='LatestDataTime', description='The point in time at which the data is last updated.', example='2023-06-01 00:00:00'),
    thisMonthConsumptionConversion?: string(name='ThisMonthConsumptionConversion', description='The carbon emissions in this month, in kgCO₂e.', example='193.47'),
    thisYearConsumptionConversion?: string(name='ThisYearConsumptionConversion', description='The carbon emissions in the year of this month, in kgCO₂e.', example='1621.06'),
    totalCarbonConsumptionConversion?: string(name='TotalCarbonConsumptionConversion', description='The total carbon emissions within the specified time range, in kgCO₂e.', example='1621.06'),
    treeConsumptionConversion?: string(name='TreeConsumptionConversion', description='Converted tree carbon absorption.', example='686.4'),
  }(name='Data', description='The returned data.'),
  requestId?: string(name='RequestId', description='The request ID.', example='88FC75E3-BFFD-50B3-988D-C08E6B795CFD'),
}

model GetSummaryDataResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetSummaryDataResponseBody(name='body'),
}

async function getSummaryDataWithOptions(tmpReq: GetSummaryDataRequest, runtime: Util.RuntimeOptions): GetSummaryDataResponse {
  Util.validateModel(tmpReq);
  var request = new GetSummaryDataShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.uids)) {
    request.uidsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.uids, 'Uids', 'json');
  }
  var query = {};
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.group)) {
    query['Group'] = request.group;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  if (!Util.isUnset(request.uidsShrink)) {
    query['Uids'] = request.uidsShrink;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetSummaryData',
    version = '2023-07-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getSummaryData(request: GetSummaryDataRequest): GetSummaryDataResponse {
  var runtime = new Util.RuntimeOptions{};
  return getSummaryDataWithOptions(request, runtime);
}

model QueryCarbonTrackRequest {
  endTime?: string(name='EndTime', description='The end of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-02-01 23:59:59.', example='2023-02-01 23:59:59'),
  filterRDAccount?: int32(name='FilterRDAccount', description='Whether to count the carbon emission details of multiple accounts. You can pass it in after opening the multi-account management. The default value and 0 is No and 1 is Yes.', example='0'),
  group?: string(name='Group', description='The statistical dimension. A value of productCode specifies that statistics are collected based on cloud service. A value of region specifies that statistics are collected based on region. A value of subUid specifies that statistics are collected based on Resource Access Management (RAM) user. If you do not specify this parameter, statistics are collected based on Alibaba Cloud account.', example='productCode'),
  startTime?: string(name='StartTime', description='The beginning of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-01-01 00:00:00.', example='2023-01-01 00:00:00'),
  topNum?: int32(name='TopNum', description='After sorting in reverse order according to the data value of the return value, only the first TopNum data will be returned. If no data is passed, all data will be returned by default.', example='10'),
  uids?: [ string ](name='Uids', description='The list of Alibaba Cloud account IDs whose data needs to be queried.(used after enabling multi-account management).'),
  useCode?: int32(name='UseCode', description='Whether the return result uses code as the identifier(0 meas not used and 1 means used). If not passed, the default code is used.

For example, when the return result is to summarize carbon emissions according to the cloud product dimension, the identifier of ECS is "ecs" when 0 is passed, and "Elastic Compute Service" when 1 is passed.', example='1'),
}

model QueryCarbonTrackShrinkRequest {
  endTime?: string(name='EndTime', description='The end of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-02-01 23:59:59.', example='2023-02-01 23:59:59'),
  filterRDAccount?: int32(name='FilterRDAccount', description='Whether to count the carbon emission details of multiple accounts. You can pass it in after opening the multi-account management. The default value and 0 is No and 1 is Yes.', example='0'),
  group?: string(name='Group', description='The statistical dimension. A value of productCode specifies that statistics are collected based on cloud service. A value of region specifies that statistics are collected based on region. A value of subUid specifies that statistics are collected based on Resource Access Management (RAM) user. If you do not specify this parameter, statistics are collected based on Alibaba Cloud account.', example='productCode'),
  startTime?: string(name='StartTime', description='The beginning of the time range to query. Specify the time in the yyyy-MM-dd HH:mm:ss format. Example: 2023-01-01 00:00:00.', example='2023-01-01 00:00:00'),
  topNum?: int32(name='TopNum', description='After sorting in reverse order according to the data value of the return value, only the first TopNum data will be returned. If no data is passed, all data will be returned by default.', example='10'),
  uidsShrink?: string(name='Uids', description='The list of Alibaba Cloud account IDs whose data needs to be queried.(used after enabling multi-account management).'),
  useCode?: int32(name='UseCode', description='Whether the return result uses code as the identifier(0 meas not used and 1 means used). If not passed, the default code is used.

For example, when the return result is to summarize carbon emissions according to the cloud product dimension, the identifier of ECS is "ecs" when 0 is passed, and "Elastic Compute Service" when 1 is passed.', example='1'),
}

model QueryCarbonTrackResponseBody = {
  data?: [ 
    {
      productCode?: string(name='ProductCode', description='The service code.', example='ecs'),
      quotaValue?: double(name='QuotaValue', description='The carbon emissions within the specified time range, in kgCO₂e.', example='1.23'),
      region?: string(name='Region', description='The region in which the cloud service resides.', example='cn-beijing'),
      statisticsDate?: long(name='StatisticsDate', description='The date when the statistics are collected, which is a timestamp in milliseconds.', example='1672502400000'),
      subUid?: string(name='SubUid', description='The ID of the RAM user.', example='251538859557084260'),
      uid?: string(name='Uid', description='The ID of the Alibaba Cloud account.', example='1665635164411336'),
    }
  ](name='Data', description='The data records.'),
  requestId?: string(name='RequestId', description='The request ID.', example='B9AA726D-92A2-5F37-8D42-6C0AA3C67C0F'),
}

model QueryCarbonTrackResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QueryCarbonTrackResponseBody(name='body'),
}

async function queryCarbonTrackWithOptions(tmpReq: QueryCarbonTrackRequest, runtime: Util.RuntimeOptions): QueryCarbonTrackResponse {
  Util.validateModel(tmpReq);
  var request = new QueryCarbonTrackShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.uids)) {
    request.uidsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.uids, 'Uids', 'json');
  }
  var query = {};
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.filterRDAccount)) {
    query['FilterRDAccount'] = request.filterRDAccount;
  }
  if (!Util.isUnset(request.group)) {
    query['Group'] = request.group;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  if (!Util.isUnset(request.topNum)) {
    query['TopNum'] = request.topNum;
  }
  if (!Util.isUnset(request.uidsShrink)) {
    query['Uids'] = request.uidsShrink;
  }
  if (!Util.isUnset(request.useCode)) {
    query['UseCode'] = request.useCode;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryCarbonTrack',
    version = '2023-07-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryCarbonTrack(request: QueryCarbonTrackRequest): QueryCarbonTrackResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryCarbonTrackWithOptions(request, runtime);
}

model QueryMultiAccountCarbonTrackRequest {
  endTime?: string(name='EndTime', example='2023-10'),
  startTime?: string(name='StartTime', example='2023-01'),
}

model QueryMultiAccountCarbonTrackResponseBody = {
  data?: [ 
    {
      carbonActualEmission?: string(name='CarbonActualEmission', example='0.0650967'),
      month?: string(name='Month', example='2023-01'),
      productCode?: string(name='ProductCode', example='ecs'),
      region?: string(name='Region', example='cn-beijing'),
      uid?: string(name='Uid', example='1665635164411336'),
    }
  ](name='Data'),
  requestId?: string(name='RequestId', description='Id of the request', example='49857457-0425-545D-A7A2-9632B43BE2CE'),
}

model QueryMultiAccountCarbonTrackResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QueryMultiAccountCarbonTrackResponseBody(name='body'),
}

async function queryMultiAccountCarbonTrackWithOptions(request: QueryMultiAccountCarbonTrackRequest, runtime: Util.RuntimeOptions): QueryMultiAccountCarbonTrackResponse {
  Util.validateModel(request);
  var query = OpenApiUtil.query(Util.toMap(request));
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryMultiAccountCarbonTrack',
    version = '2023-07-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryMultiAccountCarbonTrack(request: QueryMultiAccountCarbonTrackRequest): QueryMultiAccountCarbonTrackResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryMultiAccountCarbonTrackWithOptions(request, runtime);
}

model VerifyResponseBody = {
  data?: {
    allowedUids?: [ string ](name='AllowedUids'),
    accountType?: int32(name='accountType'),
    allMultiAccountUids?: [ 
      {
        accountId?: string(name='accountId'),
        displayName?: string(name='displayName'),
      }
    ](name='allMultiAccountUids'),
    code?: string(name='code'),
    message?: string(name='message'),
    multiAccountsAllow?: int32(name='multiAccountsAllow'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='49857457-0425-545D-A7A2-9632B43BE2CE'),
}

model VerifyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: VerifyResponseBody(name='body'),
}

async function verifyWithOptions(runtime: Util.RuntimeOptions): VerifyResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'Verify',
    version = '2023-07-11',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function verify(): VerifyResponse {
  var runtime = new Util.RuntimeOptions{};
  return verifyWithOptions(runtime);
}

